// 接口

// 1. 接口对象
export interface PersonState {
	// 必须属性
	name: string
	age: number
	// 可选属性
	sex?: string
	// 只读属性
	readonly id: number
	// 其他属性
	[propName: string]: any
}

const o: PersonState = {
	name: '张三',
	age: 18,
	id: 110,
	height: 220
}

const o1: PersonState = {
	name: '李四',
	age: 20,
	sex: '男',
	id: 120,
	like: '足球'
}

console.log(o, o1);


// 2. 接口索引(不建议)
interface ArrState {
	[propName: number]: number
}

interface ArrState1 {
	[propName: number]: string | number
}


const arr: number[] = [1, 2, 3, 4]

const arr1: ArrState = [1, 2, 3, 4, 4, 5]
const arr3: ArrState1 = ['a', 'b', 'c', 1, 2, 3, 4]

console.log(arr, arr1, arr3);


//  3. 描述函数  
interface AddState {
	(x: number, y: number): number
}

const add: AddState = (x: number, y: number): number => x + y

console.log(add);

// 4. 类 实现 接口

interface PersonClassState {
	name: string
	age: string
	sex: string
	sayName(): void
}

class Father {
	sex: string
}

class Person extends Father implements PersonClassState {
	name: string
	age: string
	constructor() {
		super()
	}
	sayName(): void {
		console.log(123)
	}
}

//  5. 接口继承

interface ObjState extends PersonClassState {
	height: number
	weight: number
	like: string

}
const obj: ObjState = {
	height: 1,
	weight: 1,
	like: '123123',
	name: '123',
	age: '123',
	sex: '123',
	sayName() {
		console.group(1231231321)
	}
}